<?php

class CvController extends Controller
{
	
	public function filters()
		{
			return array(
	              'accessControl',
			);
		}
	
		public function accessRules()
		{
			return array(
				array('allow',
	                'actions'=>array('addscope','scope','editscope','delscope'),
	                'roles'=>array('admin'),
			),
			
			
			);
		}
	
	
	public function actionIndex()
	{
		if(true)
		{
		 $page_size =11; 
         $page;         
         //$scope;
         $cv_count = Usercv::model()->count();
          $count_page=$cv_count/$page_size;
          //���� ���� ���� �� ������� ��� �������
          $scopes = Scope::model()->findAll();
	if(!isset($_GET['scope']))
	{
         if(!isset($_GET['page']))
         {         	
         		$usercv=Usercv::model()->recently(0,$page_size)->findAll();                   
         }
         else
           {
           	$page=$_GET['page'];
             $sdvig = $page_size*($page-1);
             $usercv=Usercv::model()->recently( $sdvig,$page_size)->findAll();
           }
        
	}	
	else //���� ��� ���� �� ������� ��� ������� �� ����
	{
		$scope=$_GET['scope']; 
		$cv_count = Usercv::model()->with('Scope')->count('scope=:scope',array(':scope'=>$scope));
         $count_page=$cv_count/$page_size;
	   if(!isset($_GET['page']))
         {         	
         		$usercv=Usercv::model()->with('Scope')->recently(0,$page_size)->findAll('scope',array(':scope'=>$scope));
                   
         }
         else
           {
           	$page=$_GET['page'];
             $sdvig = $page_size*($page-1);
             $usercv=Usercv::model()->with('Scope')->recently( $sdvig,$page_size)->findAll('scope=:scope',array(':scope'=>$scope));
           }
	}
    
      
   

  
    $this->render('index', array(       
        'usercv'=>$usercv,
        'count_page'=>$count_page+1,
    'scope'=>$scopes,
        
    ));
		}
		else
		{
			$slider = Information::model()->recently(0,5)->findAll();
			$uservacancy = Job::model()->recently(0,10)->findAll();
			  $this->render('application.views.site.regblock',array('uservacancy'=>$uservacancy,'information'=>$slider));
		}
	}
	
	
	
	public function actionRead()
	{
			if(true)
		{
		 $page_size =11; 
         $page;         
         //$scope;
         $cv_count = Usercv::model()->count();
          $count_page=$cv_count/$page_size;
          //���� ���� ���� �� ������� ��� �������
          $scopes = Scope::model()->findAll();
		$scope = Scope::model()->findAll();
		$id=$_GET['id'];
		$usercv=Usercv::model()->findByPk($id);
		$this->render('read',array('usercv'=>$usercv,'scope'=>$scope));
		}
		else
		{
			$slider = Information::model()->recently(0,5)->findAll();
			$uservacancy = Job::model()->recently(0,10)->findAll();
			  $this->render('application.views.site.regblock',array('uservacancy'=>$uservacancy,'information'=>$slider));
		}
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}